<?php


namespace App\Services\Agora;


class CloudPlayerService extends BaseService
{
    public function createPlayer($region = 'cn')
    {
        $uri = "/{$region}/v1/projects/{$this->appid}/cloud-player/players";
        $param = [
            'player' => [
                'streamUrl' => 'rtmp://example.agora.io/live/class32/101',
                'channelName' => '7d72365eb983485397e3e3f9d460bdda',
                'token' => '006ebd0668b2488412db416b1e9d065ff82IADhd5O+BIo0mrET+ZIcJq6yk4Q5pwXPvpOEJ6ee4KL1E7dIfRBxw6ixIgDrJwAAR7isYQQAAQDngqthAwDngqthAgDngqthBADngqth',
                'uid' => 456,
                'id' => '2a784467d647bb87b60b719f6fa56317',
                'idleTimeout' => 300,
                'name' => '7d72365eb983485397e3e3f9d460bdda'
            ]
        ];
        $res = $this->request($uri, $param);
        return $res;
    }

    /**
     * 删除指定在线媒体流
     * @param string $region
     * @param int $id
     * @return bool|mixed|string
     */
    public function deletePlayer($region = 'cn', $id = 0)
    {
        $uri = "/{$region}/v1/projects/{$this->appid}/cloud-player/players/{$id}";
        $res = $this->request($uri, [], 'DELETE');
        return $res;
    }

    /**
     * 查询项目下所有云播放器
     * @return bool|mixed|string
     */
    public function getPlayers()
    {
        $uri = "/v1/projects/{$this->appid}/cloud-player/players";
        $res = $this->request($uri, [], 'GET');
        return $res;
    }
}
